<%--
    Document   : EnrichNet
    Created on : 20-feb-2014, 9:38:50
    Author     : Juan
--%>
<%@page import="java.util.ArrayList"%>
<%@page import="archivos.Txt"%>
<%@page import="utils.OS"%>
<%@page import="java.util.List"%>
<%@page import="java.io.File"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html lang="en">
    <head>
        <%@include file="../disenoWeb/title.html" %>
        <meta charset="utf-8">
        <%@include file="../disenoWeb/head.html" %>
        <script src="../disenoWeb/js/formulario.js" type="text/javascript"></script>

    </head>
    <body>
        <div class="extra">
            <!--==============================header=================================-->
            <header>
                <%@include file="../disenoWeb/divHeader.jsp" %>
                <div class="menu-row">
                    <div class="menu-bg">
                        <div class="main">
                            <nav class="indent-left">
                                <ul class="menu wrapper">
                                    <%@include file="menuEnrich.html" %>
                                </ul>
                            </nav>
                        </div>
                    </div>
                </div>
                <div class="row-bot">
                    <div class="center-shadow">
                    </div>
                </div>
            </header>


            <div id="imagen-loader-goganpa" class="loader" style="display: none">
                <img src="../disenoWeb/images/loader.gif""/>
            </div>

            <section id="content"><div class="ic">More Website Templates @ TemplateMonster.com. December10, 2011!</div>
                <div class="content-bg">
                    <div id="formulario" class="main">
                        <%                            /*Se lee el fichero orgFA.txt para obtener la lista de todos los organismos*/
                            String separator = OS.getDirectorySeparator();
                            String ubicacion = application.getRealPath(separator + "WEB-INF" + separator + "datos");

                            List<String> listaO = new ArrayList();
                            String nombreORG = "orgFA.txt";
                            File archivoO = new File(ubicacion + separator + nombreORG);

                            /*Se recoge el organismo seleccionado para que cuando sea distinto de null
                             deje de mostrar la lista de organismos y muestre el siguiente formulario*/
                            String submit_organismo = request.getParameter("submit_organismo");
                            if (submit_organismo == null) {
                                String db = request.getParameter("db");
                                session.setAttribute("db", db);
                                if (db.equals("kegg")) {
                                    nombreORG = "orgKegg.txt";
                                    archivoO = new File(ubicacion + separator + nombreORG);
                                    listaO = Txt.listaOrg(archivoO);

                        %>

                        <form id="form_select_orgs_goganpa">
                            <h3>Organism</h3>
                            <br/>
                            <select name="orgs" required="required">

                                <%             for (int i = 1; i < listaO.size(); i = i + 2) {

                                        if (i == 1) {
                                %><optgroup label="Animals"><%
                                } else if (i == 78 * 2 + 1) {
                                    %><optgroup label="Plants"><%
                                    } else if (i == 108 * 2 + 1) {
                                    %><optgroup label="Fungis"><%
                                    } else if (i == 179 * 2 + 1) {
                                    %><optgroup label="Prototits"><%
                                        }%>
                                    <option value=<%=listaO.get(i - 1)%>><%=listaO.get(i)%></option>
                                    <%}
                                    %>
                            </select>
                            <br/>
                            <button type="submit" name="submit_organismo" value=" Aceptar ">Aceptar</button>
                        </form>

                        <%                        } else {

                            listaO = Txt.listaOrgFA(archivoO);
                            List listaC = Txt.listaOrgCFA(archivoO);

                        %>

                        <form id="form_select_orgs_goganpa">
                            <h3>Select the organism</h3>
                            <br/>
                            <select name="orgs" required="required">

                                <%             for (int i = 0; i < listaO.size(); i++) {%>


                                <option value=<%=listaC.get(i)%>><%=listaO.get(i)%></option>

                                <%}%>
                            </select>
                            <br/>
                            <button type="submit" name="submit_organismo" value=" Aceptar ">Aceptar</button>
                        </form>

                        <%                        }

                        } else {
                            /*Se coloca el organismo en session para luego utilizarlo en operaciones posteriores*/
                            String carpeta = request.getParameter("orgs");
                            session.setAttribute("carpeta", carpeta);

                        %>


                        <form method="post" id="form_select_orgs" action="enrich.jsp" enctype="multipart/form-data">
                            <h3>Genes List <img width="30px" height="30px" src="../disenoWeb/images/information.png" alt="Information2" onclick="javascript:informacionKegg()" /></h3>


                            <% if (session.getAttribute("db").equals("kegg")) { %>
                            <div id="informationKegg" style="display: none;font-size: 12px">A list of Genes (a gene for each line).<br/>
                                The correct gene's nomenclature must be "entrez genes" (vertebrate animals) or "locus tag" (rest of organisms).</div>

                            <% } else {

                                String nomenclatura = Txt.nomenclaturaFA(archivoO, carpeta);
                            %>   
                            <div id="informationKegg" style="display: none;font-size: 12px">A list of altered Genes (a gene for each line).<br/>
                                The gene's nomenclature should be "<%=nomenclatura%>"</div>
                                <% }%>

                            <input type="file" name="file" accept=".txt" required="required" />

                            <br />

                            <button type="submit" name="submit_archivo" value=" Aceptar " onclick="muestraLoadingEnrich();">Accept</button>

                        </form>
                        <% }
                        %>
                    </div>
                    <div class="block"></div>
                </div>
            </section>
        </div>




        <!--==============================footer=================================-->
        <footer>
            <%@include file="../disenoWeb/footer.html" %>
        </footer>
        <script type="text/javascript"> Cufon.now();</script>
    </body>
</html>
